import { _decorator, AudioClip, AudioSource, Component, loader, Node, resources } from 'cc';

export default class AudioTools{
    private static audioNameList = [];
    static soundEffVol = 1;
    static musicVol = 1;
    static playMusic(audioName: string, loop = false, vol = 1) {
        let source = null;
        this.playAudio(audioName, true, vol = 1);
    }
    static playAudio(audioName: string, loop:boolean = false, vol:number = 1) {
        resources.load(audioName, AudioClip, (err: Error, Aclip: AudioClip) => {
            if (err) {
                console.error("AudioTools 加载音频文件失败", audioName, err);
            } else {
                let source = new AudioSource();
                source.clip = Aclip;
                source.loop = loop;
                source.volume = vol;
                source.play();
            }
        });
    }
    static clickAudio(name:string = "click"){
        console.log(this.soundEffVol);
        AudioTools.playAudio("audio/"+name,false,this.soundEffVol);
    }
    static setSoundEffVolVol(vol){
        this.soundEffVol = vol;
    }
}


